
layui.use('laydate',function(){
	
	  var laydate = layui.laydate;
	   
	  var startTime =   laydate.render({
	      elem: '#startTime',
	      done: function(value, date){
	    	  endTime.config.min={    	    		
	      	    	year:date.year,
	      	    	month:date.month-1,//关键
	                  date:date.date,
	                  hours:date.hours,
	                  minutes:date.minutes,
	                  seconds:date.seconds
	      	    };
	      }
	    });
	    
	 var endTime =  laydate.render({
  	        elem: '#endTime',
  	        done: function(value, date){
  	        	startTime.config.max={
  	    	    		year:date.year,
  	        	    	month:date.month-1,//关键
  	                    date:date.date,
  	                    hours:date.hours,
  	                    minutes:date.minutes,
  	                    seconds:date.seconds
  	    	    }
  	        }
  	    });
		 
	});
/**
 * 从地址栏传值的代码
 * @param param
 * @returns
 */

function getParameter(param){
	var query = window.location.search;
	var iLen = param.length;
	var iStart = query.indexOf(param);
	if (iStart == -1)
		return "";
	iStart += iLen + 1;
	var iEnd = query.indexOf("&", iStart);
	if (iEnd == -1)
		return query.substring(iStart);
	return query.substring(iStart, iEnd);
}


layui.use('table', function(){
  var table = layui.table;


//监听工具条
  table.on('tool(demo)', function(obj){
    var da = obj.data;
    //删除
    if(obj.event === 'del'){
      layer.confirm('真的删除行么', function(index){
    	layer.close(index);
        obj.del();
        var url='../../listenRawstockRecord/delete.action';
        var data={"id":da.rrId};
        $.post(url,data,function(mes){
        	layer.msg(mes.msg);
        },"json");
      });
    //修改
    } else if(obj.event === 'edit'){
    	layer.open({
  		  type: 2, //设置为iframe
  		  fix: false, //不固定
		  maxmin: true,
	      shadeClose: true,
	      shade:0.4,
  		  title:'修改',
  		  area: ['400px', '450px'],
  		  content: ['InsertOrUpdate.html', 'no'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
  		  ,success: function(layero, index){
  			var url='../../listenRawstockRecord/display.action';
  	    	var data={"id":da.rrId};
  	    	var body = layer.getChildFrame('body', index);
			var iframe = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
  	    	$.post(url,data,function(mes){
  	    			iframe.$("#id").val(mes.rrId);
					iframe.$("#rrName").val(mes.rrName);
					iframe.$("#rrTime").val(mes.rrTime2);
					iframe.$("#rrNumber").val(mes.rrNumber);
					iframe.$("#rrExplain").val(mes.rrExplain);
					//调用子页面渲染的方法
					iframe.load();
  	    	},"json");
  		  },end: function(){ 
			 location.reload();
		  }    
  	  }); 
    }
  });
  //表单重载
  var $ = layui.$, active = {
		    reload: function(){
		    	 var rrName = $('#rrName');
		    	 var startTime = $('#startTime');
		    	 var endTime = $('#endTime');
		      //执行重载    查询
		      table.reload('idTest', {
		        page: {
		          curr: 1 //重新从第 1 页开始
		        }
		        ,where: {
		        	rsId: getParameter("rsId"),
		        	rrName: rrName.val(),
		        	startTime: startTime.val(),
		        	endTime: endTime.val(),
		        }
		      });
		    }
		  };
  active['reload'] ? active['reload'].call(this) : '';
  
  $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  
  /**
   * 增加
   */
   $('#insert').on('click', function(){
 	  layer.open({
 		  type: 2, //设置为iframe
 		  fix: false, //不固定
 		  maxmin: true,
 	      shadeClose: true,
 	      shade:0.4,
   		  title:'增加',
   		  area: ['400px', '450px'],
 		  content: ['InsertOrUpdate.html', 'no'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
 		  ,end: function(){ 
 			 location.reload();
 		  }    
 	  }); 
 	          
   });
});